<h2>Quote Details</h2>

<?php
    $this->headTitle('Quote Details');
        $this->headScript()->appendFile('/js/BizSense/Crud.js');   
    $quote = $this->quote;
    $quoteItems = $this->quoteItems;
    $acl = $this->acl;
?>

<?php if  ($acl->isAllowed($this->currentUser, 'access quote pages')): ?>
<a href="<?php echo $this->url(array(
            'module'        =>  'default', 
            'controller'    =>  'quote'
        ), NULL, true); ?>">Quotes</a> |
<?php endif; ?>        

<?php if  ($acl->isAllowed($this->currentUser, 'access quote pages')): ?>
<a href="<?php echo $this->url(array(
            'module'        =>  'default', 
            'controller'    =>  'quote', 
            'action'        =>  'export', 
            'quote_id'      => $this->escape($quote['quote_id'])
        ), NULL, true); ?>" target="_blank">Export To PDF</a> |
<?php endif; ?>

<?php if  ($acl->isAllowed($this->currentUser, 'access quote pages')): ?>
<a href="<?php echo $this->url(array(
            'module'        =>  'default', 
            'controller'    =>  'quote', 
            'action'        =>  'csvexport', 
            'quote_id'      => $this->escape($quote['quote_id'])
        ), NULL, true); ?>">Export To CSV</a> |
<?php endif; ?>

<?php if  ($acl->isAllowed($this->currentUser, 'edit all quotes')): ?>
<a href="<?php echo $this->url(array(
            'module'        =>  'default', 
            'controller'    =>  'quote', 
            'action'        =>  'edit', 
            'quote_id'      => $this->escape($quote['quote_id'])
        ), NULL, true); ?>">Edit</a> |
<?php endif; ?>

<?php if  ($acl->isAllowed($this->currentUser, 'delete all quotes')): 
    $deleteUrl = $this->url(
                    array(
                        'module' => 'default',
                        'controller' => 'quote',
                        'action' => 'delete',
                        'quote_id' =>$this->escape($quote['quote_id'])
                    )
                );
                echo $this->deleteButton($deleteUrl); 
 endif; ?>
|

<div class="spacer_large">
</div>

<table class="data_table">
    <tr>
        <td>quote Id</td><td><?php echo $this->escape($quote['quote_id']); ?></td>
    </tr>
    <tr>
        <td>Party type</td>
        <td>
        <?php 
            if ($quote['to_type'] == 
                Core_Model_Invoice::TO_TYPE_ACCOUNT) {
                echo 'Account';
            } else {
                echo "Contact";
            }
            echo " <br />";
          
            echo $this->partyHyperlink($this->escape($quote['to_type']), $this->escape($quote['to_type_id']));
        ?>
        </td>
    </tr>
    <tr>
        <td>Quote to</td>
        <td><?php 
                echo $this->quoteParty($this->escape($quote['to_type']), $this->escape($quote['to_type_id'])); 
            ?>
        </td>
    </tr>
    <tr>
        <td>Campaign id</td>
        <td><?php if($quote['campaign_id']) {
            echo $this->escape($this->campaignNameById($quote['campaign_id']));}
            ?></td>
    </tr>

    <tr>
        <td>Created on</td>
        <td><?php echo $this->escape(
                        $this->timestampToHuman($quote['created'])); ?></td>
    </tr>
    <tr>
        <td>Created by</td>
        <td><?php echo $this->userHyperlink(
                            $this->escape($quote['created_by'])); ?></td>
    </tr>
    <tr>
        <td>Branch</td>
        <td><?php echo $this->branchHyperlink(
                            $this->escape($quote['branch_id'])); ?></td>
    </tr>
    <tr>
        <td>Discount amount</td>
        <td><?php echo $this->escape($quote['discount_amount']); ?></td>
    </tr>
    <tr>
        <td>Total amount</td>
        <td><?php echo $this->escape($this->quoteTotal($quote['quote_id'])); ?>
        </td>
    </tr> 
    <tr>
        <td>Description</td>
        <td><?php echo $this->escape($quote['description']); ?>
        </td>
    </tr> 
    <tr>
        <td>Delivery Terms</td>
        <td><?php echo $this->escape($quote['delivery_terms']); ?>
        </td>
    </tr> 
    <tr>
        <td>Payment Terms</td>
        <td><?php echo $this->escape($quote['payment_terms']); ?>
        </td>
    </tr> 
    
    <tr>
        <td>Internal Notes</td>
        <td><?php echo $this->escape($quote['internal_notes']); ?>
        </td>
    </tr> 
    
</table>


<table class="data_table">
    <tr>
        <td class="tinyshort">Serial #</td>
        <td>Item</td>
        <td>Unit Price</td>
        <td>Quantity</td>
        <td>Tax Type</td>
        <td>Tax</td>
        <td>Total</td>
    </tr>
    <?php
        $serialNumber = 1;
        foreach ($quoteItems as $item) {
            echo "<tr>";
            echo sprintf("<td>%d</td>", $serialNumber++);
            echo "<td>";
            echo $this->escape($this->inventoryItemName(
                    Core_Model_Invoice::INVOICE_ITEM_TYPE_PRODUCT, 
                    $item['product_id']
                ));
            echo "</td>";
            $unitPrice = $this->escape($item['unit_price']);
            echo "<td>" . number_format($unitPrice, 2, '.', ',') . "</td>";
            $quantity = $item['quantity'];
            echo "<td>" . number_format($quantity, 2, '.', ',') . "</td>";
            echo "<td>" . $this->escape(
                        $this->taxNameById($item['tax_type_id'])) . "</td>";
            $taxPercentage = 
                $this->escape($this->taxPercentageById($item['tax_type_id']));
            $beforeTax = $unitPrice * $quantity;
            $tax = ($beforeTax * $taxPercentage) / 100;
            echo "<td>" . $tax . "</td>";
            $lineTotal = $beforeTax + $tax;
            echo "<td>" . number_format($lineTotal, 2, '.', ',') . "</td>";
            echo "</tr>";
        }
    ?>
</table>

<br/>

<?php
    echo "Send email with Pdf quote as attachment", "<br/>";
    echo "<br/>";
    $form = $this->form;
?>
<div id="form">
    <?php  echo $this->form; ?>
</div>
<div class="div_clear"></div>
